﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MKAdminCore.Controllers;
using MKAdminCore.ToolKit.Config;
using MKAdminCore.ToolKit.DocPreview;
using MKAdminCore.ToolKit.Extensions;

namespace MKAdminCore.Areas.File.Controllers
{
    [Area("File")]
    [Route("File/[controller]/[action]")]
    public class PreviewController : BaseMvcController
    {
        public IActionResult Index()
        {
            return View(PageViewFilesConfig.FilePreviewIndex);
        }

        /// <summary>
        /// 预览文件
        /// </summary>
        /// <param name="key"></param>
        /// <param name="catalogName"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult OnliePreview(string catalogName)
        {
            var catalogConfig = AppSettingConfigExtensions.GetUploadFileConfigInfo("Preview");

            var filePath = $"{catalogConfig.SavePath}/{catalogName}";
            var relativePath = $"{catalogConfig.SaveUrl}/{catalogName}";
            var result = OnlinePreviewHelper.OfficeDocumentToHtml(filePath, relativePath);


            return Ok(result);
        }
    }
}